import redis


class Myredis:
    def __init__(self):
        self.r=redis.Redis(host="101.42.31.212",port=6379)

    def set_srt(self,key,value):
        self.r.set(key,value)

    def setex_str(self,key,value,time):
        self.r.set(key,value,time)



    def getex_str(self,key):

        return self.r.get(key).decode() if self.r.get(key) else ""

    def get_str(self,key):
        return self.r.get(key)

    def del_str(self, key):
        return self.r.delete(key)

   #hash
    def hash_add(self,key,field,value):
        return self.r.hset(key,field,value)

    def hash_getall(self,key):
        return self.r.hgetall(key)

    def hash_getone(self,key,field):
        return self.r.hget(key,field)

    def hash_hdel(self,key,field):
        return self.r.hdel(key,field)

    def get_key(self,key):
        return self.r.keys(key)


    #list
    def list_push(self,key,value):
        return self.r.lpush(key,value)

    def list_pop(self,key):
        return self.r.rpop(key)

    def list_lrange(self,key,min,max):
        return self.r.lrange(key,min,max)

    def list_len(self,key):
        return self.r.llen(key)

    def list_del(self,key,field):
        return self.r.lrem(key,-1,field)

    def list_lpushrpop(self,list1,list2):
        return self.r.rpoplpush(list1,list2)

    # zset

    def zset_zadd(self, key, score, value):
        map = {value: score}
        return self.r.zadd(key, mapping=map)

    def zset_zrem(self, key, value):
        return self.r.zrem(key, value)

    def zset_zrangebyscore(self, key, min, max):
        return self.r.zrangebyscore(key, min, max)

r=Myredis()